package com.example.springmultipledatasourcesample.controller;

import com.example.springmultipledatasourcesample.ResponseResult;
import com.example.springmultipledatasourcesample.dbcar.Car;
import com.example.springmultipledatasourcesample.dbuser.UserInfo;
import com.example.springmultipledatasourcesample.repository.car.CarRepository;
import com.example.springmultipledatasourcesample.repository.user.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping
@Validated
public class CarController {
    @Autowired
    CarRepository carRepository;


    @Autowired
    UserRepository userRepository;
    @RequestMapping(value = {"addCar"}, method = {RequestMethod.GET})
    public ResponseResult addCarAndUser() {
        Car car = new Car();
        car.setName("三体水滴车");
        carRepository.save(car);

        UserInfo userInfo = new UserInfo();
        userInfo.setName("三体人");
        userRepository.save(userInfo);
        return new ResponseResult("添加成功");
    }

}
